export function useColor () {
  const getForeColor = (color: string, opactiy: number) => {
    let foreColor = color;
    if (foreColor === undefined || foreColor === '') {
      return 'grey';
    } else if (foreColor.startsWith('#')) {
      return hex2rgba(foreColor, opactiy);
    } else {
      return foreColor;
    }
  };

  const hex2rgba = (hex: string, opacity: number): string => { //颜色转换
    // hex格式如#ffffff
    let colorArr = [];
    for (let i = 1; i < 7; i += 2) {
      colorArr.push(parseInt('0x' + hex.slice(i, i + 2))); // 16进制值转10进制
    }
    let alpha = opacity;
    return `rgba(${colorArr.join(',')},${alpha})`;
  }

  return {
    getForeColor
  };
}
